//
//  XLMineViewController.m
//  XiangLove
//
//  Created by 陈宪栋 on 2017/11/28.
//  Copyright © 2017年 BAOMIHUA.COM. All rights reserved.
//

#import "XLMineViewController.h"
#import "BMHSettingExitCell.h"
#import "XLHeadViewCell.h"
#import "XLUserInfoModel.h"
#import "XLAccountManager.h"
#import "BMHFeedbackController.h"
#import "BMHAboutMeController.h"
#import "XLMyLevelViewController.h"
#import "XLV2LoginViewController.h"
#import <YYCache.h>
#import <YYWebImageManager.h>
#import <YYDiskCache.h>
#import "XLHTTPSessionManager+Analytics.h"
#import <ReactiveCocoa.h>
#import "TopUpViewController.h"
#import "BMHCashOutViewController.h"
#import "XLJDTableViewCell.h"
#import "XLSWTableViewCell.h"
#import "XLHTTPSessionManager+UserInfo.h"
#import <objc/runtime.h>
#import "VideoRecordViewController.h"
#import "XLPersonPageViewController.h"
#import "XLMatchViewController.h"
#import "XLOrderViewController.h"
#import "XLAnchorWorkVC.h"

#import "WXApiManager.h"
#import <WXApi.h>

#import "XLHTTPSessionManager+matchOrder.h"
#import "XLNewOrderViewController.h"
#import "XLTaskViewController.h"
#import "XLHintAwardView.h"
#import "XLArchorLeadView.h"
#import "XLAnchorCommitInforVC.h"
#import "XLJudgeDayLogin.h"
#import "XLSettingViewController.h"
#import "XLFriendsBaseVC.h"
#import "XLWhoLookMeVC.h"
#import "XLTabBarController.h"

#import "XLUserBagViewController.h"
#import "MSNewAnchorWordVC.h"

@interface UITableViewCell (click)
@property (nonatomic, copy) void(^clickBlock)(void);
@end

@implementation UITableViewCell (click)
- (void (^)(void))clickBlock {
    return objc_getAssociatedObject(self, @"clickBlock");
}

- (void)setClickBlock:(void (^)(void))clickBlock {
    objc_setAssociatedObject(self, @"clickBlock", clickBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
@end

@interface XLMineViewController ()<UITableViewDelegate, UITableViewDataSource>{
    UIView *TaskUnfinishedView;
    UIImageView *LevelImageView;
}

@property (nonatomic, strong) UITableView     *tableView;
@property (nonatomic, strong) NSArray         *dataArray;
@property (nonatomic, assign) NSInteger        bytes;
@property (nonatomic, strong) XLUserInfoModel *userInfoModel;
@property (nonatomic, copy  ) NSString        *voiceSwitchValue;
@property (nonatomic, copy  ) NSString        *isForVoicePrice;
@property (nonatomic, copy  ) NSString        *isForVideoPrice;
@property (nonatomic, copy  ) NSString        *videoHint;
@property (nonatomic, strong) UISwitch        *sw;

@property (nonatomic, strong) NSArray         *cellArray;
@property (nonatomic, strong) XLHeadViewCell  *headCell;//
@property (nonatomic, strong) UITableViewCell *LevelCell;//
@property (nonatomic, strong) UITableViewCell *TaskCell;//
@property (nonatomic, strong) UITableViewCell *shourucell;//
@property (nonatomic, strong) UITableViewCell *customerService;//
@property (nonatomic, strong) UITableViewCell *setting;//
@property (nonatomic, strong) UITableViewCell *anchorWorkCell;//
@property (nonatomic, strong) UITableViewCell *applyCell;///
@property (nonatomic, strong) UITableViewCell *yijianCell;//
@property (nonatomic, strong) UITableViewCell *lookMeCell;//
@property (nonatomic, strong) UITableViewCell *myFriendCell;//

@property (nonatomic, strong) UITableViewCell *swcell;
@property (nonatomic, strong) UITableViewCell *guanyuCell;
@property (nonatomic, strong) UITableViewCell *setCell;
@property (nonatomic,  copy ) void(^setChatSucessBlock)(void);
@property (nonatomic,  copy ) void(^setChatFailBlock)(void);

@property (nonatomic,strong)UIView            *beautyTopView;
@property (nonatomic,strong)UIImageView       *videochatTopImg;
@property (nonatomic,strong)UILabel           *redPoint;
@property (nonatomic,strong)NSMutableArray    *orderListAry;
@property (nonatomic,assign)NSInteger          orderInter;
@property (nonatomic,assign)BOOL               isAppear;

@end

@implementation XLMineViewController

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
//    XLTabBarController *tabVC = (XLTabBarController *)self.tabBarController;
//    [tabVC.launchAnimation play];
    [UserDefaults setObject:@"4" forKey:@"tabBarSelectedIndex"];
    [UserDefaults synchronize];
    self.isAppear = YES;
    if ([[[XLAccountManager shareInstance] model].IsAnchor isEqualToString:@"1"])
    {
        //[self userOderListData];
    }
    [self downloadUserInfor];
}
-(void)downloadUserInfor{
    
    [[[XLHTTPSessionManager sharedManager] getUserInfoWithUserId:[[XLAccountManager shareInstance] model].Id secretKey:[[XLAccountManager shareInstance] model].SecretKey] subscribeNext:^(XLUserInfoModel *model) {
        [UserDefaults setObject:model.Id forKey:UserID];
        [UserDefaults setObject:model.HeadImg forKey:UserHead];
        [UserDefaults setObject:model.NickName forKey:UserNick];
        model.SecretKey = [[XLAccountManager shareInstance] model].SecretKey;
        [[XLAccountManager shareInstance] updateUserInfo:model];
        [self reloadCell];
        [self setupData];
        [self.tableView reloadData];
    } error:^(NSError *error) {
        
    }];
    
}
- (void)reloadCell{
    if ([[[XLAccountManager shareInstance] model].IsAnchor isEqualToString:@"0"]) {//不是主播
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell], @[_TaskCell],@[_yijianCell, _customerService, _setting]];
        } else {
            self.cellArray = @[@[_headCell],@[_myFriendCell, _lookMeCell], @[_shourucell,_TaskCell,_LevelCell],@[_applyCell], @[_yijianCell, _customerService, _setting]];
        }
    } else {//是主播
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell], @[_yijianCell, _customerService, _setting]];
        } else {
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell,_LevelCell], @[_anchorWorkCell],@[_yijianCell, _customerService, _setting]];
        }
    }
}
- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    self.isAppear = NO;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.fd_prefersNavigationBarHidden = YES;
    self.navigationItem.title = @"我的";
    self.view.backgroundColor = kClearColor;
    [self setupView];
    [self setupCellArray];
    [self setupData];
    [self analyticsEvent1];
    if ([[[XLAccountManager shareInstance] model].IsAnchor isEqualToString:@"1"])
    {
        //[self StartGrabSingle];
    }
}

- (void)addObserver {
    @weakify(self);
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:@"OrderRefresh" object:nil] subscribeNext:^(id x) {
        @strongify(self);
        if ([[[XLAccountManager shareInstance] model].IsAnchor isEqualToString:@"1"])
        {
            if (self.isAppear) {
                [self userOderListData];
            }
        }
    }];
}

#pragma mark -
#pragma mark - 开始抢单
-(void)StartGrabSingle
{
    _beautyTopView = [[UIView alloc] init];
    _beautyTopView.backgroundColor = kClearColor;
    [self.view addSubview:_beautyTopView];
    [self hostTapGestureRecognizer:_beautyTopView];
    [_beautyTopView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right).offset(-15);
        make.bottom.equalTo(self.view.mas_bottom).offset(-20);
        make.size.mas_equalTo(CGSizeMake(48, 48));
    }];
    
    _videochatTopImg = [[UIImageView alloc] init];
    _videochatTopImg.image = [UIImage imageNamed:@"home_but_qiang2_n"];
    [_beautyTopView addSubview:_videochatTopImg];
    [_videochatTopImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(_beautyTopView);
        make.size.mas_equalTo(CGSizeMake(48, 48));
    }];
    
    _redPoint = [[UILabel alloc] init];
    _redPoint.textColor = kWhiteColor;
    _redPoint.font = kSetFont(10);
    _redPoint.layer.masksToBounds = YES;
    _redPoint.layer.cornerRadius  = 8;
    _redPoint.backgroundColor = RGBA(248, 75, 90, 1);
    _redPoint.textAlignment = NSTextAlignmentCenter;
    [_videochatTopImg addSubview:_redPoint];
    //    [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
    //        make.size.mas_equalTo(CGSizeMake(20, 16));
    //        make.center.equalTo(_videochatTopImg).centerOffset(CGPointMake(18, -9));
    //    }];
    
}

- (void)updateCellOnline
{
    NSInteger readCount = self.orderInter;
    if ( readCount <= 9 &&  readCount > 0)
    {
        _redPoint.hidden = NO;
        [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(20, 16));
            make.center.equalTo(_videochatTopImg).centerOffset(CGPointMake(18, -9));
        }];
        
    }else if (readCount >= 10) {
        _redPoint.hidden = NO;
        [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(30, 20));
            make.center.equalTo(_videochatTopImg).centerOffset(CGPointMake(18, -9));
        }];
        
    }else {
        
        [_redPoint mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(0, 0));
            make.center.equalTo(_videochatTopImg).centerOffset(CGPointMake(18, -9));
        }];
        _redPoint.hidden = YES;
        
    }
    
    [_redPoint setText:readCount > 99 ? @"99+" : [NSString stringWithFormat:@"%ld",readCount]];
    
}

-(void)hostTapGestureRecognizer:(UIView *)view
{
    UITapGestureRecognizer *tap =[[UITapGestureRecognizer alloc]initWithTarget:self     action:@selector(hostTapAction:)];
    [view addGestureRecognizer:tap];
}

#pragma mark -
#pragma mark -主播-抢单大厅
-(void)hostTapAction:(UITapGestureRecognizer *)tap
{
    //主播-抢单大厅
    NSLog(@"主播-抢单大厅");
    if ([self checkCameraAuthorization]) {
        //        [self analyticsEvent17];
        //        [self analyticsEvent18];
        //        XLOrderViewController *vc = [[XLOrderViewController alloc] init];
        //        [self.navigationController pushViewController:vc animated:YES];
        XLNewOrderViewController *vc = [[XLNewOrderViewController alloc] init];
        vc.view.backgroundColor=[UIColor colorWithWhite:0 alpha:0.77];
        vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
        [self presentViewController:vc animated:YES completion:^(void){
            vc.view.superview.backgroundColor = [UIColor clearColor];
        }];
    }
}

-(void)userOderListData
{
    [[[XLHTTPSessionManager sharedManager] getOrderListWithAnchorId:[[XLAccountManager shareInstance] model].Id] subscribeNext:^(id x) {
        NSLog(@"订单列表数据==%@",x);
        self.orderListAry = x;
        if (self.orderListAry.count > 0 || self.orderListAry.count == 0) {
            self.orderInter = self.orderListAry.count;
            [self updateCellOnline];
        }
        
    } error:^(NSError *error) {
        
    }];
}

- (UIStatusBarStyle)preferredStatusBarStyle {
    return UIStatusBarStyleDefault;
}

#pragma mark -
#pragma mark - initUI
- (void)setupView {
    self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
    self.tableView.separatorColor = RGB_HEX(0xEEEEEE);
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.sectionHeaderHeight = 10;
    self.tableView.sectionFooterHeight = 0.01;
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.view.mas_right);
        make.left.equalTo(self.view.mas_left);
        if (IS_IPhoneX) {
            make.top.equalTo(self.view.mas_top).offset(-75);
        }else{
            make.top.equalTo(self.view.mas_top).offset(-55);
        }
        make.bottom.equalTo(self.view.mas_bottom);
    }];
}



- (void)setupCellArray {
    self.userInfoModel = [[XLAccountManager shareInstance] model];
    @weakify(self);
    //1 头部
    XLHeadViewCell *headCell = [[XLHeadViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:NSStringFromClass([XLHeadViewCell class])];
    headCell.selectionStyle = UITableViewCellSelectionStyleNone;
    [headCell.headImgView sd_setImageWithURL:[NSURL URLWithString:self.userInfoModel.HeadImg] placeholderImage:nil];
    headCell.UserNameView.text = self.userInfoModel.NickName;
    headCell.UsersIdView.text = [NSString stringWithFormat:@"ID:%@",self.userInfoModel.Id];
    headCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    headCell.backgroundColor = RGB_HEX(0xffffff);
    headCell.clickBlock = ^{
        @strongify(self);
        XLPersonPageViewController *vc = [[XLPersonPageViewController alloc] init];
        vc.userId = self.userInfoModel.Id;
        [self.navigationController pushViewController:vc animated:YES];
    };
    _headCell = headCell;
    
    //2 我的好友
    UITableViewCell *myfriend = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    myfriend.selectionStyle = UITableViewCellSelectionStyleNone;
    myfriend.textLabel.font = [UIFont systemFontOfSize:16];
    myfriend.textLabel.textColor = kBlackColor;
    myfriend.detailTextLabel.font = [UIFont systemFontOfSize:16];
    myfriend.textLabel.text = @"我的好友";
    myfriend.imageView.image = [UIImage imageNamed:@"me_icon_haoyou_n"];
    myfriend.detailTextLabel.textColor = kLightGrayColor;
    myfriend.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    myfriend.backgroundColor = RGB_HEX(0xffffff);
    myfriend.clickBlock = ^{
        @strongify(self);
        XLFriendsBaseVC * topupVC = [[XLFriendsBaseVC alloc] init];
        [self.navigationController pushViewController:topupVC animated:YES];
    };
    _myFriendCell = myfriend;
    
    //3 谁看过我
    UITableViewCell *lookMe = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    lookMe.selectionStyle = UITableViewCellSelectionStyleNone;
    lookMe.textLabel.font = [UIFont systemFontOfSize:16];
    lookMe.textLabel.textColor = kBlackColor;
    lookMe.detailTextLabel.font = [UIFont systemFontOfSize:16];
    lookMe.textLabel.text = @"谁看过我";
    lookMe.imageView.image = [UIImage imageNamed:@"me_icon_kanguo_n"];
    lookMe.detailTextLabel.textColor = RGB_HEX(0xF3BA20);
    lookMe.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    lookMe.backgroundColor = RGB_HEX(0xffffff);
    lookMe.clickBlock = ^{
        @strongify(self);
        XLWhoLookMeVC * topupVC = [[XLWhoLookMeVC alloc] init];
        [self.navigationController pushViewController:topupVC animated:YES];
    };
    _lookMeCell = lookMe;
    //4 成长中心
    UITableViewCell *TaskCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    TaskCell.selectionStyle = UITableViewCellSelectionStyleNone;
    TaskCell.textLabel.font = [UIFont systemFontOfSize:16];
    TaskCell.textLabel.textColor = kBlackColor;
    TaskCell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    TaskCell.textLabel.text = @"成长中心";
    TaskCell.imageView.image = [UIImage imageNamed:@"me_icon_renwu_n"];
    TaskCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    TaskCell.backgroundColor = RGB_HEX(0xffffff);
    TaskCell.clickBlock = ^{
        @strongify(self);
        XLTaskViewController *vc = [[XLTaskViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    };
    TaskUnfinishedView = [[UIView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH - 43, 17, 10, 10)];
    TaskUnfinishedView.backgroundColor = RGB_HEX(0xFfbb01);TaskUnfinishedView.layer.cornerRadius = 5;
    [TaskCell addSubview:TaskUnfinishedView];
    _TaskCell = TaskCell;
    
    //5 改为心聊钱包
    UITableViewCell *shourucell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    shourucell.selectionStyle = UITableViewCellSelectionStyleNone;
    shourucell.textLabel.font = [UIFont systemFontOfSize:16];
    shourucell.textLabel.textColor = kBlackColor;
    shourucell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    shourucell.textLabel.text = @"想爱钱包";
    shourucell.imageView.image = [UIImage imageNamed:@"me_icon_renwu_n1"];
    //    shourucell.detailTextLabel.text = [NSString stringWithFormat:@"%@元",self.userInfoModel.TotalMoneyString];
    shourucell.detailTextLabel.textColor = RGB_HEX(0xffbb01);
    shourucell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    shourucell.backgroundColor = RGB_HEX(0xffffff);
    shourucell.clickBlock = ^{
        @strongify(self);
        XLUserBagViewController *vc = [[XLUserBagViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    };
    _shourucell = shourucell;
    //6 我的等级
    UITableViewCell *Levelcell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    Levelcell.selectionStyle = UITableViewCellSelectionStyleNone;
    Levelcell.textLabel.font = [UIFont systemFontOfSize:16];
    Levelcell.textLabel.textColor = kBlackColor;
    Levelcell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    Levelcell.textLabel.text = @"我的等级";
    Levelcell.imageView.image = [UIImage imageNamed:@"me_icon_dengji_n"];
    Levelcell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    Levelcell.backgroundColor = RGB_HEX(0xffffff);
    Levelcell.clickBlock = ^{
        @strongify(self);
        XLMyLevelViewController *vc = [[XLMyLevelViewController alloc] initWithNibName:@"XLMyLevelViewController" bundle:nil];
        vc.myJifenNumber = _userInfoModel.UserIntegralString;
        vc.mylevelNumber = _userInfoModel.UserLevelString;
        [self.navigationController pushViewController:vc animated:YES];
    };
    LevelImageView = [[UIImageView alloc]init];
    [Levelcell addSubview:LevelImageView];
    _LevelCell = Levelcell;
    //7申请主播
    UITableViewCell *applyCell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    applyCell.textLabel.font = [UIFont systemFontOfSize:16];
    applyCell.textLabel.textColor = kBlackColor;
    applyCell.textLabel.text = @"主播申请";
    applyCell.imageView.image = [UIImage imageNamed:@"me_icon_renzheng_n"];
    applyCell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    applyCell.detailTextLabel.text = @"审核中";
    applyCell.detailTextLabel.textColor = kLightGrayColor;
    applyCell.selectionStyle = UITableViewCellSelectionStyleNone;
    applyCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    applyCell.backgroundColor = RGB_HEX(0xffffff);
    applyCell.clickBlock = ^{
        @strongify(self);
        if ([_userInfoModel.Status integerValue] != -1) {
            XLAnchorCommitInforVC *vc = [[XLAnchorCommitInforVC alloc] init];
            [self.navigationController pushViewController:vc animated:YES];
        }
    };
    _applyCell = applyCell;
    //7,工作台
    UITableViewCell *AnchorWork = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    AnchorWork.textLabel.font = [UIFont systemFontOfSize:16];
    AnchorWork.textLabel.textColor = kBlackColor;
    AnchorWork.textLabel.text = @"主播工作台";
    AnchorWork.imageView.image = [UIImage imageNamed:@"me_icon_renzheng_n"];
    AnchorWork.detailTextLabel.font = [UIFont systemFontOfSize:16];
    AnchorWork.detailTextLabel.textColor = kLightGrayColor;
    AnchorWork.selectionStyle = UITableViewCellSelectionStyleNone;
    AnchorWork.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    AnchorWork.backgroundColor = RGB_HEX(0xffffff);
    AnchorWork.clickBlock = ^{
        @strongify(self);
        
        MSNewAnchorWordVC * vc = [[MSNewAnchorWordVC alloc]init];
        [self.navigationController pushViewController:vc animated:YES];
        
//        XLAnchorWorkVC *vc = [[XLAnchorWorkVC alloc] init];
//        [self.navigationController pushViewController:vc animated:YES];
    };
    _anchorWorkCell = AnchorWork;
    
    //9 意见反馈
    UITableViewCell *yijiancell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    yijiancell.selectionStyle = UITableViewCellSelectionStyleNone;
    yijiancell.textLabel.font = [UIFont systemFontOfSize:16];
    yijiancell.textLabel.textColor = kBlackColor;
    yijiancell.textLabel.text = @"意见反馈";
    yijiancell.imageView.image = [UIImage imageNamed:@"me_icon_fankui_n"];
    yijiancell.detailTextLabel.text = @"有奖";
    if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
        yijiancell.detailTextLabel.text = @"";
    }
    yijiancell.detailTextLabel.textColor = RGB_HEX(0xF3BA20);
    yijiancell.detailTextLabel.font = [UIFont systemFontOfSize:16];
    yijiancell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    yijiancell.backgroundColor = RGB_HEX(0xffffff);
    yijiancell.clickBlock = ^{
        @strongify(self);
        BMHFeedbackController *vc = [[BMHFeedbackController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    };
    _yijianCell = yijiancell;
    
    //10 官方客服
    UITableViewCell *customerService = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    customerService.selectionStyle = UITableViewCellSelectionStyleNone;
    customerService.detailTextLabel.font = [UIFont systemFontOfSize:16];
    customerService.detailTextLabel.textColor = kLightGrayColor;
    customerService.detailTextLabel.text = @"点击复制官方微信";
    customerService.textLabel.text = @"官方客服";
    customerService.imageView.image = [UIImage imageNamed:@"me_icon_kefu_n"];
    customerService.textLabel.font = [UIFont systemFontOfSize:16];
    customerService.textLabel.textColor = kBlackColor;
    customerService.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    customerService.backgroundColor = kWhiteColor;
    customerService.clickBlock = ^{
        UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
        pasteboard.string = @"xinliao999";
//        [MBProgressHUD showContent:@"官方微信号已复制"];
        
        //@"打开微信" message:@"已复制官方微信号，是否跳转微信"
//        [UIAlertView alloc] initWithTitle:@"打开微信" message:@"已复制官方微信号，是否跳转微信" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]
        
        UIAlertController *alertVc = [UIAlertController alertControllerWithTitle:@"打开微信" message:@"已复制官方微信号，是否跳转微信" preferredStyle:(UIAlertControllerStyleAlert)];
        UIAlertAction *alertCancel = [UIAlertAction actionWithTitle:@"取消" style:(UIAlertActionStyleCancel) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
            //跳转微信
            //是否有微信程序软件
            if ([WXApi isWXAppInstalled]) {
                
                NSURL *url = [NSURL URLWithString:@"weixin://"];
                
                BOOL canOpen = [[UIApplication sharedApplication] canOpenURL:url];
                
                if (canOpen) {
                    [[UIApplication sharedApplication] openURL:url];
                }
                
            }
            
        }];
        
        [alertVc addAction:alertCancel];
        [alertVc addAction:okAction];
        
        [self presentViewController:alertVc animated:YES completion:nil];
        
        
        
    };
    _customerService = customerService;
    //11 设置
    UITableViewCell *setting = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:NSStringFromClass([UITableViewCell class])];
    setting.selectionStyle = UITableViewCellSelectionStyleNone;
    setting.detailTextLabel.font = [UIFont systemFontOfSize:16];
    setting.detailTextLabel.textColor = RGB_HEX(0xff5f6d);
    setting.imageView.image = [UIImage imageNamed:@"me_icon_shezhi_n"];
    setting.textLabel.font = [UIFont systemFontOfSize:16];
    setting.textLabel.text = @"设置";setting.textLabel.textColor = kBlackColor;
    setting.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    setting.backgroundColor = kWhiteColor;
    setting.clickBlock = ^{
        @strongify(self);
        XLSettingViewController *vc = [[XLSettingViewController alloc] init];
        vc.chatStatus = _userInfoModel.IsLiveChat;
        [self.navigationController pushViewController:vc animated:YES];
    };
    _setting = setting;
    
    
    
    
    if ([[[XLAccountManager shareInstance] model].IsAnchor isEqualToString:@"0"]) {//不是主播
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell], @[_TaskCell],@[_yijianCell, _customerService, _setting]];
        } else {
            self.cellArray = @[@[_headCell],@[_myFriendCell, _lookMeCell], @[_shourucell,_TaskCell,_LevelCell],@[_applyCell], @[_yijianCell, _customerService, _setting]];
        }
    } else {//是主播
        if ([[[NSUserDefaults standardUserDefaults] objectForKey:XiangLove_IsSH] boolValue]) {//
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell], @[_yijianCell, _customerService, _setting]];
        } else {
            self.cellArray = @[@[_headCell], @[_myFriendCell, _lookMeCell], @[_shourucell,_LevelCell], @[_anchorWorkCell],@[_yijianCell, _customerService, _setting]];
        }
    }
}

- (void)setupData {
    NSString *cacheText = [self calculateCacheSize];
    self.userInfoModel = [[XLAccountManager shareInstance] model];
    self.isForVideoPrice  = self.userInfoModel.LiveChatPrice;        //视频聊天价格
    if ([_userInfoModel.TaskStatus integerValue] == 1) {
        TaskUnfinishedView.hidden = NO;
    }else{
        TaskUnfinishedView.hidden = YES;
    }
    
    if ([_userInfoModel.Status integerValue] == -1) {
        _applyCell.detailTextLabel.text = @"审核中";
        _applyCell.accessoryType = UITableViewCellAccessoryNone;
    }else{
        _applyCell.detailTextLabel.text = @"点击申请";
        _applyCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }
    [XLDownloadImageTool downloadImage:_userInfoModel.LevelIcon place:nil imageView:LevelImageView];
    if ([self.userInfoModel.NewViewed integerValue] > 0) {
        _lookMeCell.detailTextLabel.text = [NSString stringWithFormat:@"+%@",self.userInfoModel.NewViewed];
    }
    if ([self.userInfoModel.NewMyFriends integerValue] > 0) {
        _myFriendCell.detailTextLabel.text = [NSString stringWithFormat:@"+%@",self.userInfoModel.NewMyFriends];
    }
    
    //区分账户余额（用户：金豆，主播：收入）
    if ([[XLAccountManager shareInstance].model.IsAnchor isEqualToString:@"0"]) {
        _shourucell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.userInfoModel.AccountBalanceString];
    }else{
        _shourucell.detailTextLabel.text = [NSString stringWithFormat:@"%@",self.userInfoModel.TotalMoneyString];
    }
    
    
    _headCell.headImgView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    NSString *string =  [NSString stringWithFormat:@"%@",_userInfoModel.HeadImg];
    string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    NSURL *stringurl = [NSURL URLWithString:string];
    [_headCell.headImgView sd_setImageWithURL:stringurl placeholderImage:nil completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        //在这里输出下error
        NSLog(@"%@",error);
    }];
    _headCell.UserNameView.text = self.userInfoModel.NickName;
    _headCell.UsersIdView.text = [NSString stringWithFormat:@"ID:%@",self.userInfoModel.Id];
}

- (NSString *)calculateCacheSize {
    YYWebImageManager *manager = [YYWebImageManager sharedManager];
    self.bytes = [manager.cache.diskCache totalCost];
    if (self.bytes <= 0) {
        return @"0 M";
    } else if (self.bytes < 1024) {
        return F(@"%lu B", (unsigned long)self.bytes);
    } else if (self.bytes < 1024 * 1024) {
        return F(@"%.1f KB", self.bytes / 1024.0);
    } else if (self.bytes < 1024 * 1024 *  1024) {
        return F(@"%.1f M", self.bytes / 1024.0 / 1024.0);
    } else {
        return F(@"%.1f G", self.bytes / 1024.0 / 1024.0 / 1024.0);
    }
}

#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.cellArray.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    NSArray *sectionArray = self.cellArray[section];
    return sectionArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    LevelImageView.frame = CGRectMake(SCREEN_WIDTH - 62, 14, 32, 15);
    return self.cellArray[indexPath.section][indexPath.row];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        if (indexPath.row == 0) {
            return 150;
        }
        return 44;
    }else{
        return 44;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    //    else if (section == 1){
    //        return 10;
    //    }else if (section == 2){
    //        return 10;
    //    }else if (section == 3) {
    //        return 10;
    //    }else if (section == 4) {
    return 10;
    //    }
    //    return 0.01;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    UITableViewCell *cell = self.cellArray[indexPath.section][indexPath.row];
    
    if (cell.clickBlock) {
        cell.clickBlock();
    }
}


#pragma mark - analyticsEvent
- (void)analyticsEvent1 {
    [MobClick event:@"xl_my" attributes:@{@"userid" : [[XLAccountManager shareInstance] model].Id ?: @""}];
    [[[XLHTTPSessionManager sharedAnalyticsManager] analyticsModule:@"xl_my" action:@"xl_my" userId:[[XLAccountManager shareInstance] model].Id camgirlId:nil] subscribeNext:^(id x) {
    } error:^(NSError *error) {
    }];
}

#pragma mark - 检测相机的权限是否开启
- (BOOL)checkCameraAuthorization {  //检测相机是否可用和有无授权
    BOOL isCameraAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    
    if (!isCameraAvailable) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"当前设备无法使用摄像头" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
        [alert show];
        return isCameraAvailable;
    }
    BOOL isAvalible = YES;
    //ios 7.0以上的系统新增加摄像头权限检测
    if (iOS7) {
        //获取对摄像头的访问权限。
        AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
        switch (authStatus) {
                case AVAuthorizationStatusRestricted://此应用程序没有被授权访问的照片数据。可能是家长控制权限。
                break;
                case AVAuthorizationStatusDenied://用户已经明确否认了这一照片数据的应用程序访问.
                isAvalible = NO;
                break;
                case AVAuthorizationStatusAuthorized://用户已授权应用访问照片数据.
                break;
                case AVAuthorizationStatusNotDetermined://用户尚未做出了选择这个应用程序的问候
                isAvalible =[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
                break;
            default:
                break;
        }
    }
    AVAuthorizationStatus statusAudio = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio];
    if (statusAudio == AVAuthorizationStatusDenied) {
        isAvalible = NO;
    }
    
    if (!isAvalible) {
        //[self analyticsEvent14];
        NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
        NSString *appName = [infoDict objectForKey:@"CFBundleDisplayName"];
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:F(@"您关闭了%@的相机/麦克风权限，无法进行拍照。可以在手机 > 设置 > 隐私 > 相机和麦克风中开启权限。", appName) preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:NULL];
        [alert addAction:action1];
        UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
        }];
        [alert addAction:action2];
        
        
        [self presentViewController:alert animated:YES completion:NULL];
        
    }
    return isAvalible;
}


@end
